package com.dtsheep.easyexcel.config;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.dtsheep.easyexcel.po.ExpressCompany;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Style
 *
 * <p>
 *     表头样式设计
 * </p>
 *
 * @author chuanbai
 * @date 2024/5/30
 */
public class Style {

    public static void main(String[] args) {
        // 创建导出参数
        WriteSheet writeSheet = EasyExcel.writerSheet("Sheet1").build();

// 设置表头信息
        List<List<String>> head = new ArrayList<>();
        head.add(Arrays.asList("公司名称", "公司编码", "公司类型"));

// 设置表头样式
        WriteCellStyle headStyle = new WriteCellStyle();
// 设置字体
        WriteFont headFont = new WriteFont();
        headFont.setFontName("微软雅黑");
        headFont.setFontHeightInPoints((short) 12);
        headStyle.setWriteFont(headFont);
// 设置背景颜色
        headStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        headStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
// 设置边框
        headStyle.setBorderTop(BorderStyle.THIN);
        headStyle.setBorderBottom(BorderStyle.THIN);
        headStyle.setBorderLeft(BorderStyle.THIN);
        headStyle.setBorderRight(BorderStyle.THIN);

        writeSheet.setHead(head);
//        writeSheet.setHeadStyle(headStyle);

// 准备数据
        List<ExpressCompany> dataList = new ArrayList<>();
// 添加数据到 dataList

// 执行导出
        EasyExcel.write("导出文件路径", ExpressCompany.class).sheet("Sheet1").doWrite(dataList);
    }
}
